<template>
  <div>
    <!-- 面包屑 -->
    <div class="home-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item >知识图库</el-breadcrumb-item>
        <el-breadcrumb-item >实体查询</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="entityquery-content">
      <el-input placeholder="请输入查询实体" v-model="entityInput">
        <el-button slot="append" type="primary" @click="entityQuery">查询</el-button>
      </el-input>

      <div class="entityquery-content-title">
        <span>热门搜索：</span>
        <el-link type="primary" :underline="false" v-for="(item,index) in this.hotTopList" :key="index" @click="clickQuery(item.entity1)">{{item.entity1}}</el-link>&emsp;
      </div>

      <div class="entityquery-content-chart">
        <!-- 关系图 -->
        <div  style="height: 500px;">
          <span>关系图</span>
          <div style="width: 100%;height: 100%;">
            <entityquery-echarts :echartsData="echartsData"></entityquery-echarts>
          </div>
        </div>
        <!-- 关系列表 -->
        <div>
          <span>关系列表</span>
          <el-table
            :data="tableData"
            border
            style="width: 100%;">
            <el-table-column
              prop="entityOne"
              label="实体一">
            </el-table-column>
            <el-table-column
              prop="relat"
              label="关系">
            </el-table-column>
            <el-table-column
              prop="entityTwo"
              label="实体二">
            </el-table-column>
          </el-table>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import EntityqueryEcharts from './echarts/entiyQueryEcharts'
  import KMaintainApi from '@/api/kMaintainApi'
  export default{
    name:"实体查询",
    data(){
      return{
        // 实体输入
        entityInput:"",

        tableData: [],

        // 加载
        Loading:false,

        // chartsData
        echartsData:{},

        // 热门数据
        hotTopList:[]
      }
    },
    components:{
      EntityqueryEcharts
    },
    created() {
      KMaintainApi.medAnswerTop('entity').then(res => {
        if(res.data.status === "200"){
          this.hotTopList = res.data.data.records
        }
      })
    },
    methods:{
      clickQuery(entity){
        this.entityInput = entity
        this.entityQuery()
      },
      // 实体查询操作
      entityQuery(){
        this.Loading = true
        KMaintainApi.entityQuery(this.entityInput).then(res => {
          if(res.data.status === "200"){

            // 图表
            this.echartsData = res.data.data

            this.tableData = []

            // 遍历实体二
            res.data.data.to.map(val => {
              // 关系列表添加对象
              var addObject = {
                entityOne: '',
                relat: '',
                entityTwo: ''
              }
              // 实体一
              addObject.entityOne = res.data.data.entity

              addObject.entityTwo = val.entity
              addObject.relat = val.relation
              this.tableData.push(addObject)
              this.Loading = false
            })
          }
        })
      }
    }
  }
</script>

<style scoped="scoped">
  .el-button{
    border-radius: 0px;
  }
  .entityquery-content{
    background-color: #FFFFFF;
    border-radius: 8px;
    padding: 20px;
  }
  .entityquery-content-title{
    padding: 10px;
    color: rgb(98, 98, 98);
    border-bottom: 1px solid #DCDFE6;
  }
  .entityquery-content-title a{
    margin-right: 20px;
  }
  .entityquery-content-title span:nth-child(2){
    color: rgb(26, 175, 241);
  }
  .entityquery-content-chart{
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    /* align-items: center; */
    /* height: 300px; */
  }
  .entityquery-content-chart div:nth-child(1){
    flex: 3;
    /* height: 100%; */
    display: flex;
    margin-right: 30px;
    flex-direction: column;
    border: 1px solid #C0C4CC;
  }
  .entityquery-content-chart div:nth-child(2){
    flex: 1;
    height: 100%;
    border: 1px solid #C0C4CC;
  }
  .entityquery-content-chart div span{
    display: block;
    height: 40px;
    line-height: 40px;
    padding-left: 20px;
    background-color: rgb(245, 245, 245);
    box-shadow: 1px 1px 5px #909399;
  }
</style>
